const CryptoJS = require('crypto-js.js');
const aecConfig = {
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
}
const KEY="4d935c3da26e2328e0311504604497fe"
const IV="41f57be9a3b0462d"
//加密方法
function AES_EN(text) {
    var key = CryptoJS.enc.Utf8.parse(KEY)
    var iv = CryptoJS.enc.Utf8.parse(IV)
    const encrypted = CryptoJS.AES.encrypt(text, key, { iv, ...aecConfig })
    return encrypted.ciphertext.toString()
}

//解密方法
function AES_DE(text) {
    var key = CryptoJS.enc.Utf8.parse(KEY)
    var iv = CryptoJS.enc.Utf8.parse(IV)
    text = CryptoJS.enc.Hex.parse(text)
    const decrypt = CryptoJS.AES.decrypt({ ciphertext: text }, key, { iv, ...aecConfig })
    const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
    return decryptedStr.toString()
}
export {
    AES_EN, AES_DE
}
